package com.nanyang.tms.controller.company;

import com.nanyang.common.core.annotation.BindParam;
import com.nanyang.common.core.dict.CommonEnum;
import com.nanyang.common.core.domain.ApiResult;
import com.nanyang.common.core.exception.ServiceException;
import com.nanyang.common.core.page.PageBean;
import com.nanyang.tms.api.dto.request.companysender.CompanySenderAddRequest;
import com.nanyang.tms.api.dto.request.companysender.CompanySenderDelRequest;
import com.nanyang.tms.api.dto.request.companysender.CompanySenderQueryRequest;
import com.nanyang.tms.api.dto.request.companysender.CompanySenderUpdateRequest;
import com.nanyang.tms.api.dto.response.companysender.CompanySenderPageResponse;
import com.nanyang.tms.api.dto.response.companysender.CompanySenderResponse;
import com.nanyang.tms.api.service.companysender.CompanySenderRpcService;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

@RestController
@RequestMapping("/companysender")
public class CompanySenderController {

    @Reference(version = "1.0.0", timeout = 10000, check = false)
    private CompanySenderRpcService companySenderRpcService;

    /**
     * <p>listCompanySender</p>
     * <p>Description:查询列表</p>
     *
     * @param param
     * @return
     */
    @RequestMapping(value = "/list", method = RequestMethod.POST)
    @BindParam
    public ApiResult<PageBean<CompanySenderPageResponse>> listCompanySender(@BindParam @RequestBody CompanySenderQueryRequest param) {
        ApiResult<PageBean<CompanySenderPageResponse>> apiResult = companySenderRpcService.listCompanySender(param);
        if (apiResult.getCode() == CommonEnum.SYSTEM_EXCEPTION.getCode()) {
            throw new ServiceException(CommonEnum.SYSTEM_EXCEPTION.getCode(), apiResult.getMessage());
        }
        return apiResult;
    }
    /**
     * <p>listCompanySender</p>
     * <p>Description:查询根据编码</p>
     *
     * @param param
     * @return
     */
    @RequestMapping(value = "/selectByCode", method = RequestMethod.POST)
    @BindParam
    public ApiResult<CompanySenderResponse> selectByCode(@BindParam @RequestBody CompanySenderQueryRequest param) {
        ApiResult<CompanySenderResponse> apiResult = companySenderRpcService.selectByCode(param);
        if (apiResult.getCode() == CommonEnum.SYSTEM_EXCEPTION.getCode()) {
            throw new ServiceException(CommonEnum.SYSTEM_EXCEPTION.getCode(), apiResult.getMessage());
        }
        return apiResult;
    }

    /**
     * 添加-前台
     * @param param
     * @return
     */

    @RequestMapping(value = "/save", method = RequestMethod.POST)
    @BindParam
    public ApiResult<Boolean> saveCompanySender(@BindParam @RequestBody @Valid CompanySenderAddRequest param) {
        ApiResult<Boolean> apiResult = companySenderRpcService.saveCompanySender(param);
        if (apiResult.getCode() == CommonEnum.SYSTEM_EXCEPTION.getCode()) {
            throw new ServiceException(CommonEnum.SYSTEM_EXCEPTION.getCode(), apiResult.getMessage());
        }
        return apiResult;
    }
    /**
     * 修改-前台
     * @param param
     * @return
     */

    @RequestMapping(value = "/update", method = RequestMethod.POST)
    @BindParam
    public ApiResult<Boolean> updateCompanySender(@BindParam @RequestBody @Valid CompanySenderUpdateRequest param) {
        ApiResult<Boolean> apiResult = companySenderRpcService.updateCompanySender(param);
        if (apiResult.getCode() == CommonEnum.SYSTEM_EXCEPTION.getCode()) {
            throw new ServiceException(CommonEnum.SYSTEM_EXCEPTION.getCode(), apiResult.getMessage());
        }
        return apiResult;
    }
    /**
     * 删除-前台
     * @param param
     * @return
     */

    @RequestMapping(value = "/del", method = RequestMethod.POST)
    @BindParam
    public ApiResult<Boolean> delCompanySender(@BindParam @RequestBody @Valid CompanySenderDelRequest param) {
        ApiResult<Boolean> apiResult = companySenderRpcService.delCompanySender(param);
        if (apiResult.getCode() == CommonEnum.SYSTEM_EXCEPTION.getCode()) {
            throw new ServiceException(CommonEnum.SYSTEM_EXCEPTION.getCode(), apiResult.getMessage());
        }
        return apiResult;
    }

}
